﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZLDC.Common.Estate;
using System.Data;
using System.Data.SqlClient;
using ZLDC.Topo.Model.Estate;
using System.Web.UI.WebControls;

namespace ZLDC.Topo.BLL.Estate
{
    public class lp_myListUrl
    {
        public static string SqlQuery(string[] txtTypeName,string[] txtUrl,string []txtRemark,string deptid,string userid,string username)
        {
            string outmsg = "添加失败";
            int rows = 0;
            string sqlstr = "delete from lp_WorkUrl where UserID=" + userid + "; ";

            for (int i = 0; i < txtTypeName.Length; i++)
            {
                if ("" != txtTypeName[i])
                {
                    sqlstr += " insert into lp_WorkUrl (Url,UserID,UserName,TypeName,Deptid,Remark,CreateTime,CreateUser) values (";
                    string fk = "0";
                    sqlstr += " '" + txtUrl[i] + "'," + userid + ",'" + username + "','" + txtTypeName[i] + "'," + deptid + ",'" + txtRemark[i] + "',getdate()," + _Utility.GetInfoBySession().m_sUserID + ");";
                    }
            }
            using (_Database db = new _Database("estate"))
            {
                rows = ZLDC.DAL.Estate.lp_Basis.SqlQuery(sqlstr, db);
            }
            if (rows > 0)
                outmsg = "添加成功！";
            return outmsg;
        }


        public static string returnList(DataSet ds)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table id=\"tb2\"  border='0' width='500px' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
            sb.Append("<thead>");
            sb.Append("<tr>");
            sb.Append("<th align=\"center\" width=\"50\"  bgcolor='d3eaef' class='STYLE6'>");
            sb.Append("姓名");
            sb.Append("</th>");
            sb.Append("</tr>");
            sb.Append("</thead>"); sb.Append("<tr>");
            sb.Append("<td style=\"background-color:White;text-align:left\">");
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    sb.Append("<a href=\"lp_myListUrl.aspx?uesrid=" + ds.Tables[0].Rows[i]["id"] + "&username=" + ds.Tables[0].Rows[i]["user_name"] + "\">" + ds.Tables[0].Rows[i]["user_name"] + "</a>&nbsp;&nbsp;");
                   
                }
            } sb.Append("</td>");
                    sb.Append("</tr>");
            sb.Append("</table>");
            return sb.ToString();
        }

        public static string returnUrl(string userid)
        {
            string sql = "select url,userid,typename,username from lp_WorkUrl where userid="+userid+"";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            string urlname = "<a onclick='jsweburl()'>网络推广(点击添加)</a>";
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                urlname = "网络推广：";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    urlname += "<a target=\"_blank\" href=\"" + ds.Tables[0].Rows[i]["url"] + "\">" + ds.Tables[0].Rows[i]["typename"] + "</a>&nbsp;&nbsp;";

                }
            }
            
            return urlname;
        }
        public static string returnUrl1(string userid)
        {
            string sql = "select url,userid,typename,username from lp_WorkUrl where userid=" + userid + "";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            string urlname = "<a onclick='jsweburl2()'>网络推广(点击添加)</a>";
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                urlname = "网络推广：";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {

                    urlname += "<a target=\"_blank\" href=\"" + ds.Tables[0].Rows[i]["url"] + "\">" + ds.Tables[0].Rows[i]["typename"] + "</a>&nbsp;&nbsp;";

                }
            }

            return urlname;
        }
       

                                        public static string GetstringUserlist(string deptid,string type)
        {

            return "select id,t_id,user_name from v_usr_link where t_id=" + deptid + " and status not in('离职','停薪留职') and dltflg=0 "+(type=="0"?" and station!='分行经理' ":"")+" and station!='公盘' and id is not null ";
        }
    }
}
